﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using System.Configuration;
using System.Collections.Concurrent;
using System.Text;

namespace YLPublicService
{
    public abstract partial class ServiceBase<Tuser>
    {
        public static object syncObj = new object();
        /// <summary>
        /// 获取FTP服务器信息对象
        /// 服务端用户暂时写死就YLAdmin 一个用户
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public TransferModel.FtpServerInfo RequestFtpServerInfo(Guid guid)
        {
            if (!isOnline(guid))
            {
                return null;
            }
            lock (syncObj)
            {
                dynamic user = getCurrentUser(guid);
                if (user.Enabled == false)
                    return null;
                TransferModel.FtpServerInfo info = new TransferModel.FtpServerInfo();
                info.IPV4 = FtpServerIPV4;
                info.Port = FtpServerPort;
                string pwd;
                if (user is ServerUser)
                {
                    user.LoginName = "YLAdmin";
                }
                pwd = user.FTPPassword;

                // pwd = settingManager.RandomPassword(user.LoginName, randomPassLen);
                info.ClientLoginName = user.LoginName;
                info.ClientPassWord = pwd;
                return info;
            }
        }
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="loginName"></param>
        protected void disableUserOnFtp(string loginName)
        {
            settingManager.RandomPassword(loginName, randomPassLen);
        }

    }
}